using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Kaskelot.SP.Core;
using Kaskelot.SP.Services;
using Microsoft.SharePoint;
using System.Diagnostics;

namespace Kaskelot.SP.UI.Features.AdminPages
{
	/// <summary>
	/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
	/// </summary>
	/// <remarks>
	/// The GUID attached to this class may be used during packaging and should not be modified.
	/// </remarks>

	[Guid("31dffbdf-3b73-4614-8746-da0b03081ccc")]
	public class AdminPagesEventReceiver : SPFeatureReceiver
	{
		// Uncomment the method below to handle the event raised after a feature has been activated.

		public override void FeatureActivated(SPFeatureReceiverProperties properties)
		{
			Logger.LogVerbose(this, LayerNames.UI, "AdminPagesEventReceiver.FeatureActivated", "Entered");

			SPWeb web = properties.Feature.Parent as SPWeb;

			using (PageService svc = new PageService(web))
			{
				// Ensure page
				svc.CreatePage(Constants.Admin.Pages.StartPage, "Administration", Constants.PageLayouts.DetailsPage);
				// Ensure webparts
				svc.DeleteAllWebParts(Constants.Admin.Pages.StartPage);

				WebParts.AdminValkrets.AdminValkrets wp = new WebParts.AdminValkrets.AdminValkrets();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp, Constants.WebPartZones.Tab1, 0);

				WebParts.AdminForsamling.AdminForsamling wp2 = new WebParts.AdminForsamling.AdminForsamling();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp2, Constants.WebPartZones.Tab1, 1);

				WebParts.AdminValdistrikt.AdminValdistrikt wp3 = new WebParts.AdminValdistrikt.AdminValdistrikt();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp3, Constants.WebPartZones.Tab1, 2);

				WebParts.AdminStadsdel.AdminStadsdel wp4 = new WebParts.AdminStadsdel.AdminStadsdel();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp4, Constants.WebPartZones.Tab1, 3);

				WebParts.AdminMateriel.AdminMateriel wp5 = new WebParts.AdminMateriel.AdminMateriel();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp5, Constants.WebPartZones.Tab2, 0);

				WebParts.AdminFunktion.AdminFunktion wp6 = new WebParts.AdminFunktion.AdminFunktion();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp6, Constants.WebPartZones.Tab3, 0);

				WebParts.AdminGrupp.AdminGrupp wp7 = new WebParts.AdminGrupp.AdminGrupp();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp7, Constants.WebPartZones.Tab3, 1);

				WebParts.AdminPersonTyp.AdminPersonTyp wp8 = new WebParts.AdminPersonTyp.AdminPersonTyp();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp8, Constants.WebPartZones.Tab4, 0);

				WebParts.AdminByggnadTyp.AdminByggnadTyp wp9 = new WebParts.AdminByggnadTyp.AdminByggnadTyp();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp9, Constants.WebPartZones.Tab4, 1);

				WebParts.AdminVal.AdminVal wp10 = new WebParts.AdminVal.AdminVal();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp10, Constants.WebPartZones.Tab5, 0);

				WebParts.AdminBlankett.AdminBlankett wp11 = new WebParts.AdminBlankett.AdminBlankett();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp11, Constants.WebPartZones.Tab6, 0);

				WebParts.AdminFalt.AdminFalt wp12 = new WebParts.AdminFalt.AdminFalt();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp12, Constants.WebPartZones.Tab6, 1);

				WebParts.AdminTemplates.AdminTemplates wp13 = new WebParts.AdminTemplates.AdminTemplates();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp13, Constants.WebPartZones.Tab7, 0);

				WebParts.AdminKurs.AdminKurs wp14 = new WebParts.AdminKurs.AdminKurs();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp14, Constants.WebPartZones.Tab8, 0);

				WebParts.AdminIntegrationer.AdminIntegrationer wp15 = new WebParts.AdminIntegrationer.AdminIntegrationer();
				svc.AddWebPart(Constants.Admin.Pages.StartPage, wp15, Constants.WebPartZones.Tab9, 0);
			}

			Logger.LogVerbose(this, LayerNames.UI, "AdminPagesEventReceiver.FeatureActivated", "Exiting");
		}


		// Uncomment the method below to handle the event raised before a feature is deactivated.

		//public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
		//{
		//}


		// Uncomment the method below to handle the event raised after a feature has been installed.

		//public override void FeatureInstalled(SPFeatureReceiverProperties properties)
		//{
		//}


		// Uncomment the method below to handle the event raised before a feature is uninstalled.

		//public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
		//{
		//}

		// Uncomment the method below to handle the event raised when a feature is upgrading.

		//public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
		//{
		//}
	}
}
